{{!
  Copyright (c) HashiCorp, Inc.
  SPDX-License-Identifier: BUSL-1.1
}}

<KvPageHeader @breadcrumbs={{@breadcrumbs}} @secretPath={{@path}}>
  <:tabLinks>
    <li>
      <LinkTo @route="secret.index" @models={{array @backend @path}} data-test-secrets-tab="Overview">Overview</LinkTo>
    </li>
    <li>
      <LinkTo @route="secret.details" @models={{array @backend @path}} data-test-secrets-tab="Secret">Secret</LinkTo>
    </li>
    <li>
      <LinkTo
        @route="secret.metadata.index"
        @models={{array @backend @path}}
        data-test-secrets-tab="Metadata"
      >Metadata</LinkTo>
    </li>
    <li>
      <LinkTo @route="secret.paths" @models={{array @backend @path}} data-test-secrets-tab="Paths">Paths</LinkTo>
    </li>
    {{#if @canReadMetadata}}
      <li>
        <LinkTo
          @route="secret.metadata.versions"
          @models={{array @backend @path}}
          data-test-secrets-tab="Version History"
        >Version History</LinkTo>
      </li>
    {{/if}}
  </:tabLinks>
  <:toolbarActions>
  </:toolbarActions>
</KvPageHeader>

{{#if (or @metadata @subkeys.metadata)}}
  <div class="flex row-wrap gap-24 has-top-margin-l">
    <OverviewCard @cardTitle="Current version" @subText={{this.versionSubtext}} class="is-flex-1">
      <:customTitle>
        <Hds::Text::Display @weight="semibold" @size="300">
          Current version
          {{#if (not-eq this.secretState "created")}}
            <Hds::Badge
              @text={{capitalize this.secretState}}
              @type={{if (eq this.secretState "destroyed") "outlined" "inverted"}}
              @color={{if (eq this.secretState "destroyed") "critical"}}
              @icon="x"
            />
          {{/if}}
        </Hds::Text::Display>
      </:customTitle>
      <:action>
        {{#if @canUpdateData}}
          <Hds::Link::Standalone
            @text="Create new"
            @route="secret.details.edit"
            @models={{array @backend @path}}
            @icon="plus"
            @iconPosition="trailing"
            data-test-action-text="Create new"
          />
        {{/if}}
      </:action>
      <:content>
        <Hds::Text::Display @tag="p" @size="400" @weight="medium" class="has-top-margin-m">
          {{or @metadata.currentVersion @subkeys.metadata.version}}
        </Hds::Text::Display>
      </:content>
    </OverviewCard>

    {{#if (eq this.secretState "created")}}
      {{#let (or @metadata.updatedTime @subkeys.metadata.created_time) as |timestamp|}}
        <OverviewCard
          @cardTitle="Secret age"
          @subText="Current secret version age. Last updated on {{date-format timestamp}}."
          class="is-flex-1"
        >
          <:action>
            {{#if @canReadMetadata}}
              <Hds::Link::Standalone
                @text="View metadata"
                @route="secret.metadata"
                @models={{array @backend @path}}
                @icon="arrow-right"
                @iconPosition="trailing"
              />
            {{/if}}
          </:action>
          <:content>
            <Hds::Text::Display @tag="p" @size="400" @weight="medium" class="has-top-margin-m">
              {{date-from-now timestamp}}
            </Hds::Text::Display>
          </:content>
        </OverviewCard>
      {{/let}}
    {{/if}}
  </div>
{{/if}}

<Hds::Card::Container @level="mid" @hasBorder={{true}} class="has-padding-l has-top-margin-l">
  <KvPathsCard @backend={{@backend}} @path={{@path}} @isCondensed={{true}} />
</Hds::Card::Container>

{{! @subkeys is null for community edition or if a user does not have read permissions }}
{{#if @subkeys.subkeys}}
  <KvSubkeysCard @subkeys={{@subkeys.subkeys}} @isPatchAllowed={{@isPatchAllowed}} @backend={{@backend}} @path={{@path}} />
{{/if}}